#!/usr/bin/env python
# -*- coding: utf-8 -*-
import bloutch
import hexspace
import bloutch

from pygnet import client
import time

import sys

class action(object):
    playersActions={}

    @staticmethod
    def addAction(player,action):
        action.playersActions[player].append(action)

    @staticmethod
    def deleteAction(player,action):
        i=action.playersActions.index(action)
        del action.playersActions[i]
    
    def __init__(self,player):
        self.APcost = 1
        self.energyCost = 0
        self.priority = 1
        self.player = player

    def setPriority(self,priority):
        self.priority = priority

    def getPriority(self):
        return self.priority

    def doAction(self):
        # To define for each action
        return True

    def draw(self):
        # To define for each action
        pass

class move(action):
    def __init__(self,player,movedUnit,startingHex,endingHex):
        action.__init__(self,player)
        self.movedUnit = movedUnit
        self.startingHex = startingHex
        self.endingHex   = endingHex

    def doAction(self):
        if self.movedUnit in self.startingHex.units:
            pass

# Action test
if __name__ == "__main__":
    print "Action test"
    name=raw_input('name=')
    print "Please enter your coordinates:"
    x=raw_input('x=')
    y=raw_input('y=')
    print "player ",name," at (x,y)=(",x,",",y,")"

    client.init('localhost', 1979)
    
    connection = None
    
    while not connection:
        print "no connection"
        client.poll()
        for event_name, args in client.get_events():
            if event_name == 'new_connection':
                print "connection found!"
                connection = args['connection']
    
    for i in xrange(10):
        print "sending object",i
        connection.send_object('hello')
        client.poll()
        for event_name, args in client.get_events():
            print event_name, args
        time.sleep(1)
    
    client.shutdown()
